home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / RNEWS.C < prev    next >
C/C++ Source or Header  |  1991-12-07  |  3KB  |  94 lines

  1. /*
  2.       r n e w s
  3.  
  4.       Receive incoming news into the news directory.
  5.  
  6.       This procedure needs to be rewritten to perform real news
  7.       processing.  Next release(?)
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include <fcntl.h>
  15. #include <io.h>
  16.  
  17. #include "lib.h"
  18. #include "hlib.h"
  19. #include "timestmp.h"
  20.  
  21. #ifdef __TURBOC__
  22. #pragma argsused
  23. #endif
  24.  
  25. currentfile();
  26.  
  27. void main( int argc, char **argv)
  28. {
  29.  
  30.    int count = 1;
  31.    unsigned chars_read;
  32.    char filename[FILENAME_MAX], format[FILENAME_MAX], buf[BUFSIZ];
  33.    FILE *f;
  34.    long now = time(nil(long));
  35.  
  36. #if defined(__CORE__)
  37. #error  This file cannot be compiled with __CORE__ enabled!!!
  38. #endif
  39.  
  40.    banner( argv );
  41.  
  42.    if (!configure( B_NEWS ))
  43.       panic();                /* system configuration failed */
  44.  
  45.    mkfilename(filename, spooldir, LOGFILE);
  46.    if ((logfile = FOPEN(filename, "a", BINARY)) == nil(FILE))
  47.    {
  48.       fprintf(stderr,"%s: Cannot open %s, program terminating\n",
  49.                argv[0], filename);
  50.       exit( 3 );
  51.    } /* if */
  52.  
  53.    tzset();                      /* Set up time zone information  */
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                        Get output file name                        */
  57. /*--------------------------------------------------------------------*/
  58.  
  59.    mkfilename(format, newsdir, "%08.8lX.%03.3d");  /* make pattern first */
  60.  
  61.    do {
  62.       sprintf(filename, format, now, count++);  /* build real file name */
  63.       f = fopen(filename,"r");
  64.       if (f != NULL)             /* Does the file exist?             */
  65.          fclose(f);              /* Yes --> Close the stream         */
  66.    } while (f != NULL);
  67.  
  68.    printmsg(6, "rnews: Delivering incoming news into %s", filename);
  69.  
  70.    if ((f = FOPEN(filename, "w", BINARY)) == nil(FILE))
  71.    {
  72.       printmsg(0, "rnews: cannot open input");
  73.       printerr(filename);
  74.       exit(2);
  75.    }
  76.  
  77. /*--------------------------------------------------------------------*/
  78. /*                  Main loop to write the file out                   */
  79. /*--------------------------------------------------------------------*/
  80.  
  81.    setmode(fileno(stdin), O_BINARY);   /* Don't die on control-Z, etc */
  82.    while ((chars_read = fread(buf,sizeof(char), BUFSIZ, stdin)) != 0) /* wt */
  83.         fwrite(buf,sizeof(char),chars_read,f);                        /* wt */
  84.  
  85. /*--------------------------------------------------------------------*/
  86. /*                     Close open files and exit                      */
  87. /*--------------------------------------------------------------------*/
  88.  
  89.    fclose(f);
  90.    fclose(logfile);
  91.    exit(0);
  92.  
  93. } /*main*/
  94.